/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Smuggler
 */
@Entity
@Table(name = "clientes")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Clientes.findAll", query = "SELECT c FROM Clientes c"),
    @NamedQuery(name = "Clientes.findByIdCliente", query = "SELECT c FROM Clientes c WHERE c.idCliente = :idCliente"),
    @NamedQuery(name = "Clientes.findByApellido", query = "SELECT c FROM Clientes c WHERE UPPER (c.apellido) LIKE CONCAT ('%',UPPER  (:apellido),'%') ORDER BY c.apellido DESC"),
    @NamedQuery(name = "Clientes.findByNombres", query = "SELECT c FROM Clientes c WHERE c.nombres = :nombres"),
    @NamedQuery(name = "Clientes.findByDocumento", query = "SELECT c FROM Clientes c WHERE c.documento = :documento"),
    @NamedQuery(name = "Clientes.findByDocumentoCount", query = "SELECT count(c) FROM Clientes c WHERE c.documento = :documento  AND (c.idCliente != '1')"),
    @NamedQuery(name = "Clientes.findByProcedencia", query = "SELECT c FROM Clientes c WHERE c.procedencia = :procedencia"),
    @NamedQuery(name = "Clientes.findByTelefono", query = "SELECT c FROM Clientes c WHERE c.telefono = :telefono"),
    @NamedQuery(name = "Clientes.findByCelular", query = "SELECT c FROM Clientes c WHERE c.celular = :celular"),
    @NamedQuery(name = "Clientes.findByVehiculo", query = "SELECT c FROM Clientes c WHERE c.vehiculo = :vehiculo"),
    @NamedQuery(name = "Clientes.findByPatente", query = "SELECT c FROM Clientes c WHERE c.patente = :patente"),
    @NamedQuery(name = "Clientes.findByEmail", query = "SELECT c FROM Clientes c WHERE c.email = :email"),
    @NamedQuery(name = "Clientes.findByTexto", query = "SELECT c FROM Clientes c WHERE (UPPER(CONCAT(c.apellido, ' ', c.nombres, ' ', c.email, ' ', c.procedencia, ' ', c.telefono, ' ', c.celular, ' ', c.patente, ' ', c.documento, ' ')) LIKE UPPER(CONCAT('%',:texto, '%')) AND (c.idCliente != '1')) AND ((c.activo = :activo) OR (c.activo = :activo2))  ORDER BY c.apellido ASC,c.nombres ASC"),
    @NamedQuery(name = "Clientes.findByExtranjero", query = "SELECT c FROM Clientes c WHERE c.extranjero = :extranjero"),
    @NamedQuery(name = "Clientes.findByDocumentoProcedencia", query = "SELECT c FROM Clientes c WHERE c.documento = :documento AND c.procedencia = :procedencia"),
    @NamedQuery(name = "Clientes.findByObservaciones", query = "SELECT c FROM Clientes c WHERE c.observaciones = :observaciones")})
public class Clientes implements Serializable {

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idCliente")
    private Collection<Alquileres> alquileresCollection;
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idCliente")
    private Integer idCliente;
    @Basic(optional = false)
    @Column(name = "Apellido")
    private String apellido;
    @Column(name = "Nombres")
    private String nombres;
    @Basic(optional = false)
    @Column(name = "Documento")
    private String documento;
    @Column(name = "Procedencia")
    private String procedencia;
    @Column(name = "Telefono")
    private String telefono;
    @Column(name = "Celular")
    private String celular;
    @Basic(optional = false)
    @Column(name = "Vehiculo")
    private String vehiculo;
    @Column(name = "Patente")
    private String patente;
    @Column(name = "Email")
    private String email;
    @Basic(optional = false)
    @Column(name = "Extranjero")
    private String extranjero;
    @Column(name = "Observaciones")
    private String observaciones;
    @Basic(optional = false)
    @Column(name = "Activo")
    private String activo;

    public Clientes() {
    }

    public Clientes(Integer idCliente) {
        this.idCliente = idCliente;
    }

    public Clientes(Integer idCliente, String apellido, String vehiculo, String extranjero) {
        this.idCliente = idCliente;
        this.apellido = apellido;
        this.vehiculo = vehiculo;
        this.extranjero = extranjero;
    }

    public Integer getIdCliente() {
        return idCliente;
    }

    public void setIdCliente(Integer idCliente) {
        Integer oldIdCliente = this.idCliente;
        this.idCliente = idCliente;
        changeSupport.firePropertyChange("idCliente", oldIdCliente, idCliente);
    }

    public String getApellido() {
        return apellido;
    }

    public void setApellido(String apellido) {
        String oldApellido = this.apellido;
        this.apellido = apellido;
        changeSupport.firePropertyChange("apellido", oldApellido, apellido);
    }

    public String getNombres() {
        return nombres;
    }

    public void setNombres(String nombres) {
        String oldNombres = this.nombres;
        this.nombres = nombres;
        changeSupport.firePropertyChange("nombres", oldNombres, nombres);
    }

    public String getProcedencia() {
        return procedencia;
    }

    public void setProcedencia(String procedencia) {
        String oldProcedencia = this.procedencia;
        this.procedencia = procedencia;
        changeSupport.firePropertyChange("procedencia", oldProcedencia, procedencia);
    }

    public String getTelefono() {
        return telefono;
    }

    public void setTelefono(String telefono) {
        String oldTelefono = this.telefono;
        this.telefono = telefono;
        changeSupport.firePropertyChange("telefono", oldTelefono, telefono);
    }

    public String getCelular() {
        return celular;
    }

    public void setCelular(String celular) {
        String oldCelular = this.celular;
        this.celular = celular;
        changeSupport.firePropertyChange("celular", oldCelular, celular);
    }

    public String getVehiculo() {
        return vehiculo;
    }

    public void setVehiculo(String vehiculo) {
        String oldVehiculo = this.vehiculo;
        this.vehiculo = vehiculo;
        changeSupport.firePropertyChange("vehiculo", oldVehiculo, vehiculo);
    }

    public String getPatente() {
        return patente;
    }

    public void setPatente(String patente) {
        String oldPatente = this.patente;
        this.patente = patente;
        changeSupport.firePropertyChange("patente", oldPatente, patente);
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        String oldEmail = this.email;
        this.email = email;
        changeSupport.firePropertyChange("email", oldEmail, email);
    }

    public String getExtranjero() {
        return extranjero;
    }

    public void setExtranjero(String extranjero) {
        String oldExtranjero = this.extranjero;
        this.extranjero = extranjero;
        changeSupport.firePropertyChange("extranjero", oldExtranjero, extranjero);
    }

    public String getObservaciones() {
        return observaciones;
    }

    public void setObservaciones(String observaciones) {
        String oldObservaciones = this.observaciones;
        this.observaciones = observaciones;
        changeSupport.firePropertyChange("observaciones", oldObservaciones, observaciones);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCliente != null ? idCliente.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Clientes)) {
            return false;
        }
        Clientes other = (Clientes) object;
        if ((this.idCliente == null && other.idCliente != null) || (this.idCliente != null && !this.idCliente.equals(other.idCliente))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return apellido + ", " + nombres;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

    @XmlTransient
    public Collection<Alquileres> getAlquileresCollection() {
        return alquileresCollection;
    }

    public void setAlquileresCollection(Collection<Alquileres> alquileresCollection) {
        this.alquileresCollection = alquileresCollection;
    }

    public String getDocumento() {
        return documento;
    }

    public void setDocumento(String documento) {
        String oldDocumento = this.documento;
        this.documento = documento;
        changeSupport.firePropertyChange("documento", oldDocumento, documento);
    }

    public String getActivo() {
        return activo;
    }

    public void setActivo(String activo) {
        this.activo = activo;
    }
}
